using System.Collections.Generic;
using System.IO;
using BSDS.Commands.Commands.Implementation;
using BSDS.Core.Infrastructure.Logging;
using BSDS.Core.Model.Services;

namespace BSDS.Commands.Commands.Creation.Implementation
{
    public class ConvertToXmlCommandCreator : CommandCreatorBase
    {
        private readonly DataRepository dataRepository;
        private readonly Logger logger;

        public ConvertToXmlCommandCreator(DataRepository dataRepository, Logger logger)
        {
            this.dataRepository = dataRepository;
            this.logger = logger;
        }

        protected override bool Supports(Dictionary<string, string> parameters)
        {
            return parameters.Count == 1 && parameters.ContainsKey("toXML");
        }

        protected override ICommand Create(Dictionary<string, string> parameters)
        {
            var inputFilename = parameters["toXML"];
            var outputFilename = Path.GetFileNameWithoutExtension(inputFilename) + ".xml";

            return new ConvertToXmlCommand(dataRepository, logger, inputFilename, outputFilename);
        }
    }
}